﻿namespace KingerRobot.MexicoSailunMDC.SpiService;

internal class BWmsBuildingMaterialNotInWare : IWmsBuildingMaterialNotInWare
{
    public int AddNewBuildingMaterialNotInWare(string materialCode, int checkType)
    {
        var db = Db.Default;
        var result = 0;
        var notInWare = db.WmsBuildingMaterialNotInWares.Where(t => t.MaterialCode == materialCode && t.CheckType == checkType).FirstOrDefault();

        if (notInWare is null)
        {
            result = db.WmsBuildingMaterialNotInWares.Insert(new PoWmsBuildingMaterialNotInWare()
            {
                Id = XID.Nextval,
                MaterialCode = materialCode,
                CheckType = checkType,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
            });
        }
        return result;
    }


    public int DeleteNewBuildingMaterialNotInWare(string materialCode, int checkType)
    {
        var db = Db.Default;
        var result = db.WmsBuildingMaterialNotInWares.Where(t => t.MaterialCode == materialCode && t.CheckType == checkType).Delete();
        return result;
    }

    public List<PoWmsBuildingMaterialNotInWare> GetAllBuildingMaterialNotInWareByType(int checkType)
    {
        var db = Db.Default;
        var result = db.WmsBuildingMaterialNotInWares.Where(t => t.CheckType == checkType).ToList();
        return result;
    }
    public List<PoWmsBuildingMaterialNotInWare> GetAllBuildingMaterialNotInWare()
    {
        var db = Db.Default;
        var result = db.WmsBuildingMaterialNotInWares.ToList();
        return result;
    }


}

